package com.whfc.wxmp.api.mach.v1.controller;

import com.whfc.common.result.ListData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.fuum.dto.AppCorpDTO;
import com.whfc.fuum.dto.SysMachListDTO;
import com.whfc.fuum.entity.WxUser;
import com.whfc.mach.dto.AppMachTypeDTO;
import com.whfc.wxmp.api.mach.v1.service.WxmpMachOptionService;
import com.whfc.wxmp.util.RequestConetxtUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author sun_guodong
 * @description
 * @date 2020-11-30
 */
@RestController
@RequestMapping("/mp/api/v1/mach/option")
public class WxmpMachOptionController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxmpMachOptionService wxmpMachOptionService;

    @GetMapping("/corpList")
    public Result corpList(@CurrentWxUser WxUser user,
                           @RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备筛选合作单位列表", RequestConetxtUtil.getParameters());
        ListData<AppCorpDTO> listData = wxmpMachOptionService.corpList(deptId);
        return ResultUtil.success(listData);
    }

    @GetMapping(value = "/machTypeList", params = {"deptId"})
    public Result machTypeList(@CurrentWxUser WxUser user,
                               @RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取设备筛选设备类型列表", RequestConetxtUtil.getParameters());
        ListData<AppMachTypeDTO> listData = wxmpMachOptionService.machTypeList(deptId);
        return ResultUtil.success(listData);
    }

    @GetMapping("/machTypeList")
    public Result machTypeList(@CurrentWxUser WxUser user) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取可供选择的设备类型列表", RequestConetxtUtil.getParameters());
        ListData<SysMachListDTO> listData = wxmpMachOptionService.machTypeList();
        return ResultUtil.success(listData);
    }
}
